package com.flycms.module.agent.schedule;

import com.flycms.module.agent.UserAgentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author huangzt
 * @version 1.0
 * @date 2020/3/2 11:15
 */
@Component
//@Configuration
//@EnableScheduling
public class NewVisitTask {

    private final static Logger logger = LoggerFactory.getLogger(NewVisitTask.class);

    /**
     * 每天下午23:59触发 清空每日新增访客量
     */
    //@Scheduled(cron = "0 59 23 * * ?")
    private void removeNewVisitTask() {
        JdbcTemplate jdbcTemplate = UserAgentUtils.jdbcTemplate;
        /**
         * 统计属性（访客量，访问量，ip总量，新增访客）
         */
        ConcurrentHashMap<String, Long> visitViewMap = UserAgentUtils.visitViewMap;
        visitViewMap.put("new_unique_visitor", 0L);
        //更新访客数
        String sql = "update fly_visit set new_unique_visitor = 0";
        jdbcTemplate.update(sql);
        logger.info("---- 每日清除今日访客量成功，当前访客总数为：0 ----");
    }

}
